#!/bin/sh

set -u
set -e
trap onexit INT
trap onexit TERM
trap onexit EXIT

TMPDIR=

onexit()
{
	if [ ! "$TMPDIR" = "" ]; then
		rm -rf $TMPDIR
	fi
}

if [ -f libjpeg-turbo-2.0.4.x86_64.rpm ]; then
	rm -f libjpeg-turbo-2.0.4.x86_64.rpm
fi

umask 022
TMPDIR=`mktemp -d /tmp/libjpeg-turbo-build.XXXXXX`

mkdir -p $TMPDIR/RPMS
ln -fs `pwd` $TMPDIR/BUILD
rpmbuild -bb --define "_blddir $TMPDIR/buildroot" --define "_topdir $TMPDIR" \
	--target x86_64 pkgscripts/rpm.spec; \
cp $TMPDIR/RPMS/x86_64/libjpeg-turbo-2.0.4-20211027.x86_64.rpm \
	libjpeg-turbo-2.0.4.x86_64.rpm
